import {
	ip
} from "./getinfo"
import userstore from '@/store/userlogin.js'
const request = (data) => {
	return new Promise((res, rej) => {
		const useuserstore=userstore()
		uni.showLoading({

		})
		uni.request({
			...data,
			header: {
				token: useuserstore.token|| ""
			},
			url: ip + data.url,
			success(data) {
				if (data.statusCode == 401) {
					uni.showToast({
						title: "请重新登录！",
						icon: "none",
						success() {
							setTimeout(() => {
								uni.reLaunch({
									url: "/pages/login/login"
								})
							}, 1000)
						}
					})
				}
				return res(data.data)
			},
			fail(err) {
				return rej(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}
export default request